/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucm;

import java.sql.ResultSet;
import sql.SELECT_SQL;
import view.DomeMain_View;
import view.PSW_View;

/**
 *
 * @author 马凯
 */
public class CheckStaff_UC {

    private static CheckStaff_UC cuc;
    private String cid;
    private String psw;
    private ResultSet rs;
    private PSW_View pv;

    public static CheckStaff_UC getInstance(PSW_View pv) {
        if (cuc == null) {
            cuc = new CheckStaff_UC();
            cuc.cid = pv.getPswModel().getCid();
            cuc.psw = pv.getPswModel().getPsw();
            cuc.pv = pv;
        }else{
            cuc.cid = pv.getPswModel().getCid();
            cuc.psw = pv.getPswModel().getPsw();
            cuc.pv = pv;
        }
        return cuc;
    }

    public void run() {
        String sqlQuery = "SELECT * FROM rfid WHERE cid='" + cid + "' and password = '" + psw + "';";
        System.out.println(sqlQuery);
        rs = SELECT_SQL.getInstance().run(sqlQuery);
        try {
            if (rs.first()) {
                //sqlQuery = "SELECT * FROM rfid WHERE cid='" + cid + "' and password = '" + psw + "';";
                DomeMain_View dmv = new DomeMain_View();
                dmv.setVisible(true);
                pv.setVisible(false);
                pv.getViewModel().getMv().setVisible(false);
            }else{
                pv.setVisible(false);
                pv.getViewModel().getMv().setVisible(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
